
// pages/transactionPage/transactionPage.js
//var http = require('../../utils/httpHelper.js');
var wallet = require('../wallet.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
      activeId:1,// 1买 2卖
      typeId:1,
      fadeFlag:false,
      transLang:{},
      buyId:3,
      transactionData:{},
      tid:'3'
  },
  goNav(e) {
    console.log(e)
    let id = e.currentTarget.id
    this.setData({
      tid: id
    })
    switch (id) {
      case '1':
        wx.reLaunch({
          url: '../assetPage/assetPage'

        })
        break;
      case '2':
        wx.reLaunch({
          url: '../marketPage/marketPage'
        })
        break;
      case '3':
        break;
      case '4':
        wx.reLaunch({
          url: '../myPages/myPages'
        })
        break;
      default:
        break;
    }
  },
  closeChange(e){
    this.setData({
      fadeFlag:false
    })
  },
  openCoin(e){
    this.setData({
      fadeFlag:true
    })
  },
  choiceType(e){//选择币种
   let id =  e.target.id;
   this.setData({
     typeId:id
   })
  },
  getBalance(){
    var $this = this
    var token = wx.getStorageSync('createUser').access_token; 
    var address = wx.getStorageSync('addressETH')
    wallet.post('currency/balance', { access_token: token, coin_symbol: 'ETH', wallet_addr: address}, function (res) {
        console.log(res)
        $this.setData({
          transactionData: res.data
        })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   this.getBalance && this.getBalance()
  },
  orderlist(e){
    // console.log(e.target.id);
    let id = e.target.id;
    this.setData({
          activeId:id
    })
  
  },
  orderGo(e){
    if (this.data.activeId == 1) {
      wx.navigateTo({
        url: './buycoin/buycoin?sale='+this.data.buyId//3,中文 4，英文
      })
    } else if (this.data.activeId == 2) {
      wx.navigateTo({
        url: './salecoin/salecoin'
      })
    }
  },
  IssueGo(){//去发布
    wx.navigateTo({
      url: './issueGo/issueGo'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //console.log(wx.T)
    this.setData({
      transLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en'],
      buyId: wx.T.locale == "zh-Hans" ?3:4
    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].JLTabBarTransactionText : wx.T.locales['en'].JLTabBarTransactionText
    })
   // console.log(this.data.transLang)
     wx.setTabBarItem({
      index: 2,
      text: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].JLTabBarTransactionText : wx.T.locales['en'].JLTabBarTransactionText,
      iconPath: "image/tab_jiaoyi_normal.png",
      selectedIconPath: "image/tab_jiaoyi_selected.png"
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }

})